home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 9719 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.0 KB  |  71 lines

  1. Path: realtime.net!usenet
  2. From: rflores@bga.com (Roberto Flores)
  3. Newsgroups: comp.lang.c
  4. Subject: Need Help using DLL with 'C'
  5. Date: 12 Mar 1996 22:32:21 GMT
  6. Organization: Real/Time Communications Internet customer posting
  7. Message-ID: <4i4u1l$sv1@news2.realtime.net>
  8. NNTP-Posting-Host: jake-7n.aip.realtime.net
  9. Mime-Version: 1.0
  10. X-RTcode: 4921b769317553793945fb3b
  11. X-Newsreader: WinVN 0.93.11
  12.  
  13. My background is UNIX/C w/ ESQL. but now I am developing for Windows 
  14. 3.1. I am using MSVC++ 1.5.  I have successfully used a DLL 
  15. (GETENVAR.DLL) in a Powerbuilder application to retrieve values of DOS 
  16. environment variables.  I need to be able to do the same using 'C'.  
  17. Attached is the code I am using to do this.  I maybe off base, so please
  18. help!  I am building a quick working prototype using the MS QuickWin 
  19. option.  The code finds the DLL using the GetProcAddress 
  20. function successfully, but I do not know to use the function. The 
  21. function in the DLL I want to use is:
  22.  
  23.           GetEnvironmentVar("<Environment-Variable>", rtn_string);
  24.  
  25. Code follows:
  26.  
  27.    #include <stdio.h>
  28.    #include <windows.h>
  29.    
  30.    void main ()
  31.    {
  32.     void prtvar(char *text1);
  33.        
  34.        prtvar("USERID");
  35.    }
  36.    
  37.    void prtvar(text1)
  38.    char *text1;
  39.    {                   
  40.       char *rtn_envar;
  41.       char *envar;
  42.       
  43.       HINSTANCE hinstGetEnVar;
  44.       BOOL (FAR *lpfnGetEnvironmentVar);
  45.                      
  46.       sprintf(envar, text1);
  47.       printf("%s: ", envar);
  48.       hinstGetEnVar = LoadLibrary("GETENVAR.DLL");
  49.       
  50.       if ( hinstGetEnVar > HINSTANCE_ERROR ) {
  51.            (FARPROC) lpfnGetEnvironmentVar = GetProcAddress(hinstGetEnVar, 
  52. "GetEnvironmentVar");
  53.            if (lpfnGetEnvironmentVar != NULL ) {
  54.              /* I need to use the function here.  */
  55.                printf("%s\n", rtn_envar );
  56.            }
  57.            else
  58.               printf("Find Function Failed\n");
  59.       }
  60.       FreeLibrary( hinstGetEnVar );
  61.    }
  62.  
  63. Please help by replying to:
  64.  
  65.     rflores@bga.com  or Robert.Flores@tpwd.state.tx.us
  66.  
  67. Thanks A Bunch!
  68.  
  69. Robert Flores
  70.  
  71.